package com.platform.web.controller.module;

import com.platform.common.annotation.Log;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.core.page.TableDataInfo;
import com.platform.common.enums.BusinessType;
import com.platform.common.utils.poi.ExcelUtil;
import com.platform.module.domain.TempRecord;
import com.platform.module.service.IBaseRoomTempService;
import com.platform.module.service.ITempRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 室温采集数据Controller
 * 
 * @author wangqi
 * @date 2020-07-28
 */
@Controller
@RequestMapping("/module/temp/record")
public class TempRecordController extends BaseController
{
    private String prefix = "module/temp/record";

    @Autowired
    private ITempRecordService tempRecordService;

    @Autowired
    private IBaseRoomTempService baseRoomTempService;

    @RequiresPermissions("module:temp:record:view")
    @GetMapping("/{brtId}")
    public String record(@PathVariable("brtId") String brtId, ModelMap mmap)
    {
        if(brtId.equals("0")) {
            brtId = "";
        }
        mmap.put("brtId", brtId);
        return prefix + "/record";
    }

    /**
     * 查询室温采集数据列表
     */
    @RequiresPermissions("module:temp:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TempRecord tempRecord)
    {
        startPage();
        List<TempRecord> list = tempRecordService.selectTempRecordList(tempRecord);
        return getDataTable(list);
    }

    /**
     * 导出室温采集数据列表
     */
    @RequiresPermissions("module:temp:record:export")
    @Log(title = "室温采集数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TempRecord tempRecord)
    {
        List<TempRecord> list = tempRecordService.selectTempRecordList(tempRecord);
        ExcelUtil<TempRecord> util = new ExcelUtil<TempRecord>(TempRecord.class);
        return util.exportExcel(list, "室温采集器");
    }
}
